package com.tqz.rc.server.push;

import com.tqz.rc.common.util.StringUtils;

import java.net.DatagramPacket;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 *
 * @author tianqingzhao
 * @since 2021/9/9 16:51
 */
public class AckEntry {

    private String key;
    private DatagramPacket origin;
    private Map<String, Object> data;

    private AtomicInteger retryTimes = new AtomicInteger(0);

    public AckEntry(String key, DatagramPacket origin) {
        this.key = key;
        this.origin = origin;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public DatagramPacket getOrigin() {
        return origin;
    }

    public void setOrigin(DatagramPacket origin) {
        this.origin = origin;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public void increaseRetryTime() {
        retryTimes.incrementAndGet();
    }

    public int getRetryTimes() {
        return retryTimes.get();
    }

    public static String getAckKey(String host, int port, long lastRefTime) {
        return StringUtils.trim(host) + "," + port + "," + lastRefTime;
    }
}
